<template>
	<view class="mainpadding2">
		<view class="mainpadding_top ffffff titletext bold radius flexbetween">
			<view class="hei_text">可用人數</view>
			<view class="huang_text">{{data.staff_count}}</view>
		</view>
		<view class="flexbetween flex_wrap">
			<view
				:class="item.id==currentid?'itemcheck flexcolumn mainpadding_top':'itemnocheck flexcolumn mainpadding_top'"
				v-for="item in buylist" :key="item.id" @click="currentid=item.id;paymoney=item.money">
				<view class="titletext bold" :class="item.id==currentid?'huang_text':'hei_text'"
					style="font-size: 40rpx;">{{item.money}}元</view>
				<view class="main_size hei_text bold margin_top1">{{item.num}}人</view>
				<view class="main_size hei_text bold margin_top1">{{item.day}}天</view>
			</view>
		</view>
		<view class="mainpadding posibottom" style="bottom: 0;">
			<view class="xiaohuang flexcenter titletext" @click="jumpurl('/pages/my/goumaijl')">購買記錄</view>
			<view class="submitbtn margin-top"  @click="submit">立即支付</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: '',
				type: 0,
				currentid: "",
				paymoney: "",
				buylist: []
			}
		},
		onLoad() {
			
			this.getbuylist()
		},
		onShow() {
			this.get()
		},
		methods: {
			async get() {
				let res = await this.http.request('/api/shop/Shopdeail', 'POST', {
					shop_id: uni.getStorageSync("shop_id"),
				})
				if (res.code == 1) {
					uni.setStorageSync("appkey", res.data.appkey)
					uni.setStorageSync("hy_type", res.data.hy_type)
					uni.setStorageSync("opentable_status", res.data.opentable_status)
					uni.setStorageSync("is_sdkfp", res.data.is_sdkfp)
					uni.setStorageSync("houtel_type",res.data.houtel_type)
					this.data = res.data
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			async getbuylist() {
				let res = await this.http.request('/api/shop/getmuserbuy', 'POST', {
					shop_id: uni.getStorageSync("shop_id"),
				})
				if (res.code == 1) {
					this.buylist = res.data
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			async submit() {
				if (this.currentid == "") {
					this.http.toast("請選擇購買套餐")
					return false
				}
				uni.navigateTo({
					url: "/pages/my/payment?paytype=1&paymoney=" + this.paymoney+"&id="+this.currentid
				})
				// let res = await this.http.request('/api/shop/addbuyuser', 'POST', {
				// 	id:this.currentid,
				// 	shop_id: uni.getStorageSync("shop_id"),
				// })
				// if (res.code == 1) {
				// 	this.http.toast("購買成功")
				// 	this.get()
				// } else if (res.code == 0) {
				// 	this.http.toast(res.msg)
				// } else {
				// 	this.http.toast('系統處理中，請稍後再試');
				// }
			}
		}
	}
</script>

<style lang="scss" scoped>
	.itemcheck {
		border: 1rpx solid #FF5C00;
		background-color: rgba(250, 234, 225, .9);
		width: 48%;
		border-radius: 20rpx;
	}

	.itemnocheck {
		border: 1rpx solid #E0DCDD;
		background-color: rgba(248, 246, 247, .3);
		width: 48%;
		border-radius: 20rpx;
	}
</style>